package com.wee.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigtotoro.UILImageLoader;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.wee.aircoach_user.R;
import com.wee.entity.Coach_project;
import com.wee.fragment.find.StsAdapter;

import java.util.List;

/**
 * Created by Solomon on 2015/11/25.
 */
public class CourseAdapter1 extends BaseAdapter{

    private Context context;
    private List<Coach_project> data;
    private DisplayImageOptions options;


    public CourseAdapter1(Context context, List<Coach_project> data) {
        this.context = context;
        this.data = data;

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.find1_nococah)
                .showImageForEmptyUri(R.drawable.find1_nococah)
                .showImageOnFail(R.drawable.find1_nococah)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                        //.displayer(new RoundedBitmapDisplayer(Color.WHITE, 5))
                .build();
        UILImageLoader.initImageLoader(context.getApplicationContext());
    }

    @Override
    public int getCount() {
        return data.size();
    }


    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try{
            ViewHolder holder1 ;
            if(convertView==null){
                holder1 = new ViewHolder();
                LayoutInflater inflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflate.inflate(R.layout.item_course, null);
                holder1.back = (ImageView)convertView.findViewById(R.id.plan_fengmian);
                holder1.img = (ImageView)convertView.findViewById(R.id.cocah_photo);
                holder1.name = (TextView)convertView.findViewById(R.id.cocah_name);
                holder1.tianshu = (TextView)convertView.findViewById(R.id.tianshu);
                holder1.suit_people = (TextView)convertView.findViewById(R.id.suit_people);
                holder1.cocah_jibie = (TextView)convertView.findViewById(R.id.cocah_jibie);
                holder1.plan_name=(TextView)convertView.findViewById(R.id.plan_name);
                convertView.setTag(holder1);
            }else{
                holder1 = (ViewHolder)convertView.getTag();
            }
            Coach_project coach = data.get(position);


            ImageLoader.getInstance().displayImage(coach.getCoach().getFigure(), holder1.img, options);
         //   holder1.name.getPaint().setFakeBoldText(true);
            holder1.name.setText("" + coach.getCoach().getName());
            holder1.suit_people.setText("" + coach.getDiscription());
            holder1.cocah_jibie.setText("" + coach.getCoach().getTitle());
            holder1.plan_name.getPaint().setFakeBoldText(true);
            holder1.plan_name.setText("" + coach.getName());
            holder1.tianshu.setText("" + coach.getDefault_count());
            ImageLoader.getInstance().displayImage(coach.getFigure_preview()+"", holder1.back, options);

         //   ImageLoader.getInstance().displayImage(coach.getFigure(), holder1.back);
        }catch (Exception r){}
        return convertView;}
    static class ViewHolder{
        ImageView img,back;
        TextView name,plan_name,suit_people,cocah_jibie,tianshu;
    }
}
